#include <SDL/SDL_image.h>
#include "ButtonManager.h"
#include "MainWindow.h"
#include "SinglePlayerScreen.h"
#include "MultiPlayerScreen.h"
#include "SelectScreen.h"

SelectScreen::SelectScreen()
: m_miniGame(NULL)
{
	m_miniGame = new MiniGame(MainWindow::Screen());
}

SelectScreen::~SelectScreen()
{
	ButtonManager::Instance().clearButtons();
	delete m_miniGame;
}

void SelectScreen::init()
{
	m_background.Surface = IMG_Load("images\\SelectScreenBackground.png");

	m_buttonSinglePlayer = new PushButton(this, "Single");
	m_buttonSinglePlayer->setPosition(336, 300);
	m_buttonSinglePlayer->CallBack = &On_buttonSingle_pressed;
	ButtonManager::Instance().addButton(m_buttonSinglePlayer);

	m_buttonMultiPlayer = new PushButton(this, "Multiplayer");
	m_buttonMultiPlayer->setPosition(336, 340);
	m_buttonMultiPlayer->CallBack = &On_buttonMultiPlayer_pressed;
	ButtonManager::Instance().addButton(m_buttonMultiPlayer);
	
	m_buttonQuit = new PushButton(this, "Quit");
	m_buttonQuit->setPosition(336, 380);
	m_buttonQuit->CallBack = &On_buttonQuit_pressed;
	ButtonManager::Instance().addButton(m_buttonQuit);
}

bool SelectScreen::draw()
{
	SDL_Surface* screen = MainWindow::Screen();
	
	SDL_BlitSurface(m_background.Surface, NULL, screen, NULL);
	ButtonManager::Instance().draw(screen);
	m_miniGame->draw();
	return (true);
}

void SelectScreen::doEvents()
{
	SDL_Event& e = MainWindow::Event();

	if (e.type == SDL_QUIT)
		MainWindow::Close(true);
	if (ButtonManager::Instance().update() == false)
		return ;
	m_miniGame->doEvents();
}

bool On_buttonSingle_pressed(IScreen* _screen)
{
	MainWindow::SelectScreen(new SinglePlayerScreen);
	return (false);
}

bool On_buttonMultiPlayer_pressed(IScreen* _screen)
{
	MainWindow::SelectScreen(new MultiPlayerScreen);
	return (false);
}

bool On_buttonQuit_pressed(IScreen* _screen)
{
	MainWindow::Close(true);
	return (true);
}
